package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
     private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {
        //1.调用mapper接口，获取统计数据
         List<Map<String , Object>> list = empMapper.countEmpJobData();
          List<String> jobList= list.stream().map(map -> map.get("pos").toString()).toList();
          List<String> dataList= list.stream().map(map -> map.get("num").toString()).toList();

          return  new JobOption(jobList,dataList);


    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public StudentOption getStudentCountData() {
        List<Map<String , Object>> list = studentMapper.countStudentCountData();
          List<String> clazzList= list.stream().map(map -> map.get("cla").toString()).toList();
          List<String> dataList= list.stream().map(map -> map.get("num").toString()).toList();

        return new StudentOption(clazzList, dataList);


    }

    @Override
    public List<Map> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }
}
